home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / ArrayPrivate.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  2.6 KB  |  88 lines

  1. /* Array definitions for the use of subclass implementations only
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.  
  7.    This file is part of the GNU Objective C Class Library.
  8.  
  9.    This library is free software; you can redistribute it and/or
  10.    modify it under the terms of the GNU Library General Public
  11.    License as published by the Free Software Foundation; either
  12.    version 2 of the License, or (at your option) any later version.
  13.    
  14.    This library is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.    Library General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU Library General Public
  20.    License along with this library; if not, write to the Free
  21.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */ 
  23.  
  24. #ifndef __ArrayPrivate_h_INCLUDE_GNU
  25. #define __ArrayPrivate_h_INCLUDE_GNU
  26.  
  27. #include <objects/stdobjects.h>
  28. #include <objects/IndexedCollectionPrivate.h>
  29.  
  30. #define DEFAULT_ARRAY_CAPACITY 2
  31. #define DEFAULT_ARRAY_GROW_FACTOR 2
  32.  
  33.  
  34. /* Routines that help with inserting and removing elements */
  35.  
  36. /* Assumes that _count has already been incremented to make room
  37.    for the hole.  The data at _contents_array[_count-1] is not part
  38.    of the collection). */
  39. static inline void
  40. makeHoleAt(Array *self, unsigned index)
  41. {
  42.   int i;
  43.  
  44.   for (i = (self->_count)-1; i > index; i--)
  45.     self->_contents_array[i] = self->_contents_array[i-1];
  46. }
  47.  
  48. /* Assumes that _count has not yet been decremented.  The data at
  49.    _contents_array[_count-1] is part of the collection. */
  50. static inline void
  51. fillHoleAt(Array *self, unsigned index)
  52. {
  53.   int i;
  54.  
  55.   for (i = index; i < (self->_count)-1; i++)
  56.     self->_contents_array[i] = self->_contents_array[i+1];
  57. }
  58.  
  59. /* These are the only two routines that change the value of the instance 
  60.    variable _count, except for "-initWithType:capacity:" and "-empty" */
  61.  
  62. /* Should these be methods instead of functions?  Doing so would make 
  63.    them slower. */
  64.  
  65. /* Do this before adding an element */
  66. static inline void 
  67. incrementCount(Array *self)
  68. {
  69.   (self->_count)++;
  70.   if (self->_count == self->_capacity)
  71.     {
  72.       [self setCapacity:(self->_capacity) * self->_grow_factor];
  73.     }
  74. }
  75.  
  76. /* Do this after removing an element */
  77. static inline void
  78. decrementCount(Array *self)
  79. {
  80.   (self->_count)--;
  81.   if (self->_count < (self->_capacity) / self->_grow_factor)
  82.     {
  83.       [self setCapacity:(self->_capacity) / self->_grow_factor];
  84.     }
  85. }
  86.  
  87. #endif /* __ArrayPrivate_h_INCLUDE_GNU */
  88.